var EuropeanLanguageInputMethod = InputMethod.extend({
	helping: false,
	target_list: 'ShiftNum',
	candlist: null,
	suggest_list: null,

	constructor: function()
	{
	},
	IMName: function()
	{
		return 'EuropeanLanguageInputMethod';
	},
	GetDict: function()
	{
		return null;
	},
	IsValidKey: function(key)
	{
		return false;
	},
	IsEndingKey: function(key)
	{
		return false;
	},
	IsStartingKey: function(key)
	{
		return false;
	},
	onDictNotFound: function(word)
	{
		return false;
	},
	onEnterHelping: function()
	{
	},
	onLeaveHelping: function()
	{
	},
	onActive: function()
	{
		helping = false;
	},
	EnterHelping: function()
	{
		this.onEnterHelping();
		this.helping = true;
		this.ime.ResetPreedit();
		this.suggest_list = null;
		this.UpdateCandidate();
		Debug.present && Debug.trace(1,"EuropeanInputMethod: Enter Helping mode.");
	},
	CancelHelping: function()
	{
		this.onLeaveHelping();
		this.helping = false;
		this.ime.ResetPreedit();
		this.suggest_list = null;
		this.UpdateCandidate();
		Debug.present && Debug.trace(1,"EuropeanInputMethod: Leave Helping mode.")
	},
	ListSelectHandler: function(obj,pos)
	{
		var len = this.ime.GetPreeditLength();
		var out = this.suggest_list[pos];
		
		out = out.substring(len);
		this.ime.SendString(obj,out);
		this.suggest_list = null;
		this.CancelHelping();
		return true;
	},
	UpdateCandidate: function()
	{
		var x = this;

		if(this.helping) {
			if(this.candlist) {
				this.candlist.UpdateList(this.suggest_list);
			}
			else {
				this.candlist = this.ime.candwin.OccupyList(this,this.target_list);
				if(!this.candlist) return;

				this.candlist.SetList(null,this.suggest_html_list,function(obj,pos) { return x.ListSelectHandler(obj,pos); });
				this.candlist.SetCancelHandler(function() { x.candlist = null; return true; });
			}
			this.ime.candwin.SetStatus(null);
		}
		else {
			this.ime.candwin.ReleaseList(this,this.target_list);
			this.candlist = null;
		}
		this.ime.candwin.UpdateCandidate();
	},
	GenerateSuggest: function()
	{
		if(this.helping) {
			if(this.ime.GetPreeditLength() > 0) {
				var preedit = this.ime.GetPreedit();
				var dict = this.GetDict();
				var list,key,c;
				
				this.suggest_list = new Array();
				list = dict.find(preedit);
				c = 0;
				for(key in list) {
					entry = list[key];
					this.suggest_list.push(key);
					c++;
				}
				if(c==0) {
					if(!this.onDictNotFound(preedit)) this.suggest_list = null;
				}
			}
			this.UpdateCandidate();
		}
	},
	keydown_handler: function(obj,key,m)
	{
		if(!GownFullBrowserDetect.backspace_keypress && key == 8) { // backspace
			if(this.helping) {
				this.ime.DeletePreedit(1,1);
				if(this.ime.GetPreeditLength() == 0) this.CancelHelping();
				else this.GenerateSuggest();
			}
		}
		else if(key == 9) {
			if(this.helping) {
				if(m == Const.KEY_SHIFT) {
					this.ime.SendString(obj,"\t");
					this.CancelHelping();
					return false;
				}
				else if(m == 0) { // expand
					var dict = this.GetDict();
					var preedit = this.ime.GetPreedit();
					var ex;
					
					ex = dict.expand(preedit);
					if(ex && ex.length > 0) {
						this.ime.AppendPreedit(ex,ex);
						this.ime.SendString(obj,ex);
					}
					return false;
				}
				else return true;
			}
		}
		return true;
	},
	keypress_handler: function(obj,key,m)
	{
		if(this.IsStartingKey(key,m)) {
			if(!this.helping) this.EnterHelping();
		}
		if(this.IsEndingKey(key,m)) {
			if(this.helping) this.CancelHelping();
		}
		if(GownFullBrowserDetect.backspace_keypress && key == 8) { // backspace
			if(this.helping) {
				this.ime.DeletePreedit(1,1);
				if(this.ime.GetPreeditLength() == 0) this.CancelHelping();
				else {
					this.GenerateSuggest();
				}
			}
		}
		if(this.IsValidKey(key,m)) {
			if(this.helping) {
				var ch = this.KeyMap(key,m);
				this.ime.AppendPreedit(ch,ch);
				this.ime.SendString(obj,ch);
				this.GenerateSuggest();
				return false;
			}
		}
		return true;
	}
});